home *** CD-ROM | disk | FTP | other *** search
- class smashing.keithm.Renderable
- {
- var mc;
- var baseWidth;
- var baseHeight;
- var hdWidth;
- var hdHeight;
- var radius;
- var doUpdate;
- var owner;
- var __DEF_ASSET;
- var assetID;
- var startX;
- var startY;
- var startZ;
- var depthInfluence;
- var flipH;
- var threedScale;
- var isSpawned;
- var x;
- var nextX;
- var y;
- var nextY;
- var z;
- var __onscreen;
- var isDrawn;
- var isAlive;
- var isHidden;
- var scale;
- var startScale;
- var __fastScale;
- var hdReg;
- var nextZ;
- var TYPE = "element";
- var DRAWTYPE = "element";
- var __DEF_Z = 1000;
- var __3D_SCALE = false;
- var __DEF_WIDTH = 50;
- var __DEF_HEIGHT = 50;
- var __USE_ACTUAL_DIMENSIONS = true;
- var __CAREFUL_DRAW = false;
- var CUSTOMDRAW = false;
- var __FORCE_INITAL_DRAW = false;
- var __DRAW_ON_SPAWN = false;
- var __DEF_HD_WIDTH = 25;
- var __DEF_HD_HEIGHT = 25;
- var __USE_DIMENSIONS_AS_HD = true;
- var __DO_UPDATE = true;
- function Renderable(t_data)
- {
- this.mc = null;
- this.baseWidth = this.__DEF_WIDTH;
- this.baseHeight = this.__DEF_HEIGHT;
- if(this.__USE_DIMENSIONS_AS_HD)
- {
- this.hdWidth = this.baseWidth / 2;
- this.hdHeight = this.baseHeight / 2;
- this.radius = this.hdWidth;
- }
- else
- {
- this.hdWidth = this.__DEF_HD_WIDTH / 2;
- this.hdHeight = this.__DEF_HD_HEIGHT / 2;
- this.radius = this.hdWidth;
- }
- this.setHDRegistration();
- this.doUpdate = this.__DO_UPDATE;
- this.init(t_data);
- }
- function init(t_data)
- {
- if(t_data.owner == undefined)
- {
- trace("ERROR! NO OWNER SENT TO ELEMENT : " + this.TYPE);
- }
- this.owner = t_data.owner;
- if(t_data.asset == undefined)
- {
- t_data.asset = this.__DEF_ASSET;
- }
- this.assetID = t_data.asset;
- if(t_data.x == undefined)
- {
- t_data.x = 0;
- }
- this.startX = t_data.x;
- if(t_data.y == undefined)
- {
- t_data.y = 0;
- }
- this.startY = t_data.y;
- if(t_data.z == undefined)
- {
- t_data.z = this.__DEF_Z;
- }
- this.startZ = t_data.z;
- if(t_data.depthInfluence == undefined)
- {
- t_data.depthInfluence = 0;
- }
- this.depthInfluence = t_data.depthInfluence;
- if(t_data.camera != undefined)
- {
- this.initScale(t_data.camera);
- }
- else if(this.owner.camera != undefined)
- {
- this.initScale(this.owner.camera);
- }
- else
- {
- trace("ERROR! NO CAMERA SENT TO ELEMENT : " + this.TYPE);
- }
- if(t_data.flip != undefined)
- {
- this.flip();
- }
- else
- {
- this.flipH = false;
- }
- this.threedScale = this.__3D_SCALE;
- this.isSpawned = false;
- }
- function spawn(camera)
- {
- this.isSpawned = true;
- this.reset();
- if(this.__FORCE_INITAL_DRAW)
- {
- smashing.keithm.Viewport.getInstance().draw({element:this});
- }
- else if(this.__DRAW_ON_SPAWN)
- {
- if(camera == undefined)
- {
- trace("ERROR: spawn of " + this.assetID + " failed because __DRAW_ON_SPAWN is true, but no camera was supplied.");
- return undefined;
- }
- this.updateDraw(camera);
- }
- }
- function reset()
- {
- this.x = this.nextX = this.startX;
- this.y = this.nextY = this.startY;
- this.z = this.startZ;
- this.__onscreen = false;
- if(this.mc == undefined || this.mc == null || this.mc == "")
- {
- this.isDrawn = false;
- }
- this.isAlive = true;
- this.isHidden = false;
- }
- function onDraw(t_newmc)
- {
- this.isDrawn = true;
- this.mc = t_newmc;
- if(this.isHidden)
- {
- this.mc._visible = false;
- }
- if(this.__USE_ACTUAL_DIMENSIONS)
- {
- this.baseWidth = this.mc._width;
- this.baseHeight = this.mc._height;
- this.setHDRegistration();
- if(this.__USE_DIMENSIONS_AS_HD)
- {
- this.hdWidth = this.baseWidth / 2;
- this.hdHeight = this.baseHeight / 2;
- this.radius = this.hdWidth;
- }
- }
- if(this.flipH)
- {
- this.mc._xscale = -100;
- }
- this.scale = this.startScale;
- this.mc._x = -1000 - this.baseWidth;
- this.mc._y = -1000 - this.baseHeight;
- }
- function update(dt)
- {
- }
- function move(dt)
- {
- }
- function moveAndRender(camera, dt)
- {
- }
- function updateMoveAndRender(camera, dt)
- {
- }
- function render(camera, dt)
- {
- this.updateDraw(camera);
- if(!this.isDrawn)
- {
- return undefined;
- }
- if(this.threedScale)
- {
- if(this.z < camera.z)
- {
- return undefined;
- }
- this.__fastScale = camera.fl / (this.z - camera.z);
- if(this.scale != this.__fastScale)
- {
- this.scale = this.__fastScale;
- this.mc._xscale = this.mc._yscale = 100 * (1 + (this.scale - this.startScale));
- if(this.flipH)
- {
- this.mc._xscale *= -1;
- }
- }
- }
- this.mc._x = (this.x - camera.x) * this.scale + camera.sc.x;
- this.mc._y = (this.y - camera.y) * this.scale + camera.sc.y;
- }
- function renderDirect(camera)
- {
- this.mc._x = this.x;
- this.mc._y = this.y;
- }
- function initScale(camera)
- {
- this.startScale = this.scale = camera.fl / (this.startZ - camera.z);
- }
- function updateDraw(camera)
- {
- this.__onscreen = false;
- if(this.CUSTOMDRAW)
- {
- this.__onscreen = true;
- }
- else if(this.z >= camera.z)
- {
- if(camera.z < 0)
- {
- this.__onscreen = true;
- }
- else if(Math.abs(this.x - camera.x) < camera.sc.x + this.baseWidth && Math.abs(this.y - camera.y) < camera.sc.y + this.baseHeight && this.z - camera.z < camera.farClip)
- {
- this.__onscreen = true;
- }
- }
- if(!this.isDrawn && this.__onscreen)
- {
- smashing.keithm.Viewport.getInstance().draw({element:this});
- }
- else if(this.isDrawn && !this.__onscreen)
- {
- this.requestErase();
- }
- }
- function onErase(t_viewport)
- {
- this.isDrawn = false;
- this.mc = null;
- }
- function despawn()
- {
- this.isAlive = false;
- this.isSpawned = false;
- }
- function requestErase()
- {
- smashing.keithm.Viewport.getInstance().erase({element:this});
- }
- function requestDepthSort()
- {
- smashing.keithm.Viewport.getInstance().requestGroupDepthSort(this.getDrawType());
- }
- function requestDepthChange()
- {
- smashing.keithm.Viewport.getInstance().requestDepthChange(this);
- }
- function deleteMe()
- {
- false;
- }
- function kill()
- {
- this.isAlive = false;
- }
- function hide()
- {
- if(this.isDrawn)
- {
- this.mc._visible = false;
- }
- this.isHidden = true;
- }
- function show()
- {
- if(this.isDrawn)
- {
- this.mc._visible = true;
- }
- this.isHidden = false;
- }
- function flip()
- {
- this.flipH = true;
- if(this.isDrawn)
- {
- this.mc._xscale = -100;
- }
- }
- function unflip()
- {
- this.flipH = false;
- if(this.isDrawn)
- {
- this.mc._xscale = 100;
- }
- }
- function toggleFlip()
- {
- if(this.flipH)
- {
- this.unflip();
- }
- else
- {
- this.flip();
- }
- }
- function setHDRegistration()
- {
- this.hdReg = {};
- this.hdReg.x = 0;
- this.hdReg.y = 0;
- }
- function runHD_entity_radius(t_target, dt)
- {
- var _loc4_ = this.nextX + this.hdReg.x - (t_target.nextX + t_target.hdReg.x);
- var _loc3_ = this.nextY + this.hdReg.y - (t_target.nextY + t_target.hdReg.y);
- var _loc5_ = Math.sqrt(_loc4_ * _loc4_ + _loc3_ * _loc3_);
- if(_loc5_ <= t_target.radius + this.radius)
- {
- return true;
- }
- return false;
- }
- function runHD_entity_box(t_target, dt)
- {
- if(Math.abs(this.nextX + this.hdReg.x - (t_target.nextX + t_target.hdReg.x)) < this.hdWidth + t_target.hdWidth)
- {
- if(Math.abs(this.nextY + this.hdReg.y - (t_target.nextY + t_target.hdReg.y)) < this.hdHeight + t_target.hdHeight)
- {
- return true;
- }
- }
- return false;
- }
- function runHD_entity_3D(t_target, dt)
- {
- var _loc3_ = this.z - t_target.z;
- var _loc2_ = this.nextZ + this.radius - t_target.z;
- if(_loc3_ * _loc2_ <= 0)
- {
- return this.runHD_entity_radius(t_target,dt);
- }
- return false;
- }
- function runHD_line_sphere(t_lineStart, t_lineEnd, dt)
- {
- var _loc4_ = new smashing.Point3D(t_lineStart.x,t_lineStart.y,0);
- var _loc3_ = new smashing.Point3D(t_lineEnd.x,t_lineEnd.y,0);
- var _loc6_ = _loc4_.x - _loc3_.x;
- var _loc7_ = _loc4_.y - _loc3_.y;
- var _loc2_ = this.getLineSeperation(_loc3_,{x:this.x,y:this.y},_loc6_,_loc7_);
- var _loc5_ = undefined;
- if(_loc2_.distance <= this.radius)
- {
- _loc5_ = new smashing.Point3D(this.x + _loc2_.xSeparation,this.y + _loc2_.ySeparation);
- return true;
- }
- _loc5_.x = _loc5_.y = 0;
- return false;
- }
- function runHD_line_sphere_complex(t_lineStart, t_lineEnd, dt)
- {
- var _loc5_ = new smashing.Point3D(t_lineStart.x,t_lineStart.y,0);
- var _loc7_ = new smashing.Point3D(t_lineEnd.x,t_lineEnd.y,0);
- var _loc8_ = undefined;
- var _loc16_ = this.getDistBetween(_loc5_,{x:this.x,y:this.y});
- var _loc15_ = this.getDistBetween(_loc7_,{x:this.x,y:this.y});
- var _loc11_ = this.getDistBetween(_loc5_,_loc7_);
- var _loc4_ = new smashing.Point3D(_loc5_.x,_loc5_.y);
- var _loc9_ = new smashing.Point3D(_loc7_.x,_loc7_.y);
- var _loc12_ = _loc9_.x - _loc4_.x;
- var _loc13_ = _loc9_.y - _loc4_.y;
- var _loc3_ = _loc12_ / _loc11_;
- var _loc2_ = _loc13_ / _loc11_;
- var _loc10_ = undefined;
- _loc4_.subtractScalarMe(_loc3_ * this.radius,_loc2_ * this.radius);
- _loc9_.addScalarMe(_loc3_ * this.radius,_loc2_ * this.radius);
- var _loc6_ = this.getLineSeperation(_loc5_,{x:this.x,y:this.y},_loc12_,_loc13_);
- _loc12_ = _loc9_.x - _loc4_.x;
- _loc13_ = _loc9_.y - _loc4_.y;
- var _loc14_ = this.getLineSeperation(_loc4_,{x:this.x,y:this.y},_loc12_,_loc13_);
- if(_loc6_.distance <= this.radius)
- {
- if(_loc15_ > _loc11_)
- {
- _loc8_ = Math.sqrt(this.radius * this.radius - _loc14_.distance * _loc14_.distance);
- _loc3_ *= _loc8_;
- _loc2_ *= _loc8_;
- this.x + _loc14_.xSeparation + _loc3_;
- _loc10_ = this.y + _loc14_.ySeparation + _loc2_;
- }
- else
- {
- _loc8_ = Math.sqrt(this.radius * this.radius - _loc6_.distance * _loc6_.distance);
- _loc3_ *= _loc8_;
- _loc2_ *= _loc8_;
- this.x + _loc6_.xSeparation + _loc3_;
- _loc10_ = this.y + _loc6_.ySeparation + _loc2_;
- if(this.getDistBetween(_loc5_,_loc10_) >= _loc11_)
- {
- _loc10_.copy(_loc7_);
- }
- }
- return true;
- }
- _loc10_.x = _loc10_.y = 0;
- return false;
- }
- function getLineSeperation(p0, s, dx, dy)
- {
- var _loc1_ = new Object();
- var _loc5_ = p0.x - s.x;
- var _loc6_ = p0.y - s.y;
- var _loc7_ = dx * dx + dy * dy;
- var _loc2_ = (- (_loc5_ * dx + _loc6_ * dy)) / _loc7_;
- _loc2_ = Math.min(Math.max(_loc2_,0),1);
- _loc1_.xSeparation = _loc5_ + _loc2_ * dx;
- _loc1_.ySeparation = _loc6_ + _loc2_ * dy;
- _loc1_.distance = Math.sqrt(_loc1_.xSeparation * _loc1_.xSeparation + _loc1_.ySeparation * _loc1_.ySeparation);
- return _loc1_;
- }
- function getDistBetween(p0, p1)
- {
- return Math.sqrt((p1.x - p0.x) * (p1.x - p0.x)) + (p1.y - p0.y) * (p1.y - p0.y);
- }
- function hitReact(t_source)
- {
- }
- function getDrawType()
- {
- return this.DRAWTYPE;
- }
- function animate(t_frame, t_subFrame)
- {
- this.mc.gotoAndStop(t_frame);
- if(t_subFrame != undefined)
- {
- this.mc.anim.gotoAndStop(t_subFrame);
- }
- }
- function toString()
- {
- return "Renderable: " + this.TYPE;
- }
- function drawHitBox()
- {
- var _loc3_ = this.hdReg.x;
- var _loc4_ = this.hdReg.y;
- var _loc2_ = this.mc.createEmptyMovieClip("hitbox",1);
- _loc2_.beginFill(16751103,50);
- _loc2_.lineStyle(2,16751103,100);
- _loc2_.moveTo(_loc3_ - this.hdWidth,_loc4_ - this.hdHeight);
- _loc2_.lineTo(_loc3_ + this.hdWidth,_loc4_ - this.hdHeight);
- _loc2_.lineTo(_loc3_ + this.hdWidth,_loc4_ + this.hdHeight);
- _loc2_.lineTo(_loc3_ - this.hdWidth,_loc4_ + this.hdHeight);
- _loc2_.lineTo(_loc3_ - this.hdWidth,_loc4_ - this.hdHeight);
- _loc2_.endFill();
- }
- function drawReg()
- {
- var _loc2_ = this.mc.createEmptyMovieClip("hitbox",1);
- _loc2_.beginFill(16751103,50);
- _loc2_.lineStyle(2,16751103,100);
- _loc2_.moveTo(-5,-5);
- _loc2_.lineTo(5,-5);
- _loc2_.lineTo(5,5);
- _loc2_.lineTo(-5,5);
- _loc2_.lineTo(-5,-5);
- }
- }
-